import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.PriorityQueue;


/**
 * compareable对类的侵入性大
 * 建大堆的时候o2在前面，底层的意思是如果第一个数大于的第二个数直接break而不进行比较
 * 看底层先通过offer然后再通过，siftUp看
 */
class Intcmp implements Comparator<Integer>{
	@Override
	public int compare(Integer o1, Integer o2) {
		return o2.compareTo(o1);
	}
}
class Intcmp1 implements Comparator<Integer> {
	@Override
	public int compare(Integer o1, Integer o2) {
		return o1.compareTo(o2);
	}
}
public class TestPriorityQueue {
	/**
	 * 建大堆
	 * @param args
	 */
	public static void main(String[] args) {
		int [] array={4,1,9,2,8,0,7,3,6,5};
		PriorityQueue<Integer> pq=new PriorityQueue<>(array.length,new Intcmp());
		PriorityQueue<Integer> pq1=new PriorityQueue<>(array.length,new Intcmp1());
		for (int tmp:array
			 ) {
			pq1.offer(tmp);
		}
		for (int x:array
			 ) {
			pq.offer(x);
		}
		System.out.println("===========");

	}
	public static void main1(String[] args) {
		int [] array={4,1,9,2,8,0,7,3,6,5};
		PriorityQueue<Integer> pq=new PriorityQueue<>(array.length);
		for (int x:array) {
			pq.offer(x);//默认的是一个小堆
		}
		System.out.println(pq.size());
		System.out.println(pq.peek());
		pq.poll();
		pq.poll();
		//System.out.println(Arrays.toString(array));
		pq.offer(-1);
		System.out.println(pq.peek());

		pq.clear();//直接全部清空
		if(pq.isEmpty()) {
			System.out.println("111111111111");
		} else {
			System.out.println("222222222222222");
		}
	}
}
